package org.jeecg.modules.common;

import org.apache.commons.lang.math.RandomUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author panchenxiao
 * @Email Mister_pan@126.com
 * @Date 2023/12/8 15:07
 */
public class CommonUtil {

    private static final Lock lock = new ReentrantLock();

    /**
     * 生成编号
     * cheng
     * 2022-09-21
     *
     * @return
     */
    public static String createNo(String prefix) {
        String value = "";
        lock.lock();
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
            int random = RandomUtils.nextInt(90) + 10;
            value = prefix + format.format(new Date()) + random;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
        return value;
    }
}
